// https://umijs.org/config/
import { defineConfig, utils } from 'umi';
import defaultSettings from './defaultSettings';
import proxy from './proxy';
import webpackPlugin from './plugin.config';

const { winPath } = utils; // preview.pro.ant.design only do not use in your production ;
// preview.pro.ant.design 专用环境变量，请不要在你的项目中使用它。

const { ANT_DESIGN_PRO_ONLY_DO_NOT_USE_IN_YOUR_PRODUCTION, REACT_APP_ENV, GA_KEY } = process.env;
export default defineConfig({
  hash: true,
  antd: {},
  analytics: GA_KEY
    ? {
        ga: GA_KEY,
      }
    : false,
  dva: {
    hmr: true,
  },
  locale: {
    // default zh-CN
    default: 'zh-CN',
    // default true, when it is true, will use `navigator.language` overwrite default
    antd: true,
    baseNavigator: true,
  },
  dynamicImport: {
    loading: '@/components/PageLoading/index',
  },
  targets: {
    ie: 11,
  },
  // umi routes: https://umijs.org/docs/routing
//   path: '/todo',//url中path部分，http://localhost:8000/todo状态跌幅到这个页面
// name: 'todo', //名称，国际化菜单配置根据这个名称来配置，如果不配置将直菜单将直接显示这个名称
// icon: 'unordered-list',//菜单图标名称
// component:'./todo'// 组件（页面）相对于src/pages的路径
  routes: [
    {
      path: '/',
      component: '../layouts/BlankLayout',
      routes: [
        // 账户相关布局
        {
          path: '/user',
          component: '../layouts/UserLayout',
          routes: [
            {
              path: '/user',
              redirect: '/user/login',
            },
            {
              name: 'login',
              icon: 'smile',
              path: '/user/login',
              component: './user/login',
            },
            {
              name: 'register-result',
              icon: 'smile',
              path: '/user/register-result',
              component: './user/register-result',
            },
            {
              name: 'register',
              icon: 'smile',
              path: '/user/register',
              component: './user/register',
            },
            {
              component: '404',
            },
          ],
        },
       // 基础布局
        {
          path: '/',
          component: '../layouts/BasicLayout',
          Routes: ['src/pages/Authorized'],
          authority: ['admin', 'admin1','user'],
          routes: [
            {
              path: '/dashboard',
              name: '人员管理',
              icon: 'dashboard',
              authority: ['admin', 'admin1'],
              routes: [
                // {
                //   name: 'analysis',
                //   icon: 'smile',
                //   path: '/dashboard/analysis',
                //   component: './dashboard/analysis',
                // },
                {
                  name: '用户列表',
                  icon: 'smile',
                  // 路由路径是唯一的,一般设置和组件真实路径一致
                  path: '/dashboard/user-list',
                  // 组件路径一定是真实的相对路径
                  component: './dashboard/user-list',
                  authority: ['admin', 'admin1'],

                },
                // {
                //   name: 'monitor',
                //   icon: 'smile',
                //   path: '/dashboard/monitor',
                //   component: './dashboard/monitor',
                // },
                // {
                //   name: 'workplace',
                //   icon: 'smile',
                //   path: '/dashboard/workplace',
                //   component: './dashboard/workplace',
                // },
              ],
            },
            {
              path: '/form',
              icon: 'form',
              name: '班级管理',
              routes: [
                {
                  name: '班级列表',
                  icon: 'smile',
                  path: '/form/basic-form',
                  component: './form/basic-form',
                  authority: ['admin'],
                },
                {
                  name: '我的班级',
                  icon: 'smile',
                  path: '/form/step-form',
                  component: './form/step-form',
                  authority:['admin1','user']
                },
                // {
                //   name: 'advanced-form',
                //   icon: 'smile',
                //   path: '/form/advanced-form',
                //   component: './form/advanced-form',
                // },
              ],
            },
            // {
            //   path: '/list',
            //   icon: 'table',
            //   name: 'list',
            //   routes: [
            //     {
            //       path: '/list/search',
            //       name: 'search-list',
            //       component: './list/search',
            //       routes: [
            //         {
            //           path: '/list/search',
            //           redirect: '/list/search/articles',
            //         },
            //         {
            //           name: 'articles',
            //           icon: 'smile',
            //           path: '/list/search/articles',
            //           component: './list/search/articles',
            //         },
            //         {
            //           name: 'projects',
            //           icon: 'smile',
            //           path: '/list/search/projects',
            //           component: './list/search/projects',
            //         },
            //         {
            //           name: 'applications',
            //           icon: 'smile',
            //           path: '/list/search/applications',
            //           component: './list/search/applications',
            //         },
            //       ],
            //     },
            //     {
            //       name: 'table-list',
            //       icon: 'smile',
            //       path: '/list/table-list',
            //       component: './list/table-list',
            //     },
            //     {
            //       name: 'basic-list',
            //       icon: 'smile',
            //       path: '/list/basic-list',
            //       component: './list/basic-list',
            //     },
            //     {
            //       name: 'card-list',
            //       icon: 'smile',
            //       path: '/list/card-list',
            //       component: './list/card-list',
            //     },
            //   ],
            // },
            {
              path: '/profile',
              name: '考试管理',
              icon: 'profile',
              routes: [
                {
                  name: '考试列表',
                  icon: 'table',
                  path: '/profile/basic',
                  component: './profile/basic',
                },
                // {
                //   name: 'advanced',
                //   icon: 'smile',
                //   path: '/profile/advanced',
                //   component: './profile/advanced',
                // },
              ],
            },
            // {
            //   name: 'result',
            //   icon: 'CheckCircleOutlined',
            //   path: '/result',
            //   routes: [
            //     {
            //       name: 'success',
            //       icon: 'smile',
            //       path: '/result/success',
            //       component: './result/success',
            //     },
            //     {
            //       name: 'fail',
            //       icon: 'smile',
            //       path: '/result/fail',
            //       component: './result/fail',
            //     },
            //   ],
            // },
            // {
            //   name: 'exception',
            //   icon: 'warning',
            //   path: '/exception',
            //   routes: [
            //     {
            //       name: '403',
            //       icon: 'smile',
            //       path: '/exception/403',
            //       component: './exception/403',
            //     },
            //     {
            //       name: '404',
            //       icon: 'smile',
            //       path: '/exception/404',
            //       component: './exception/404',
            //     },
            //     {
            //       name: '500',
            //       icon: 'smile',
            //       path: '/exception/500',
            //       component: './exception/500',
            //     },
            //   ],
            // },
            {
              name: '账号安全',
              icon: 'user',
              path: '/account',
              routes: [
                {
                  name: '修改密码',
                  icon: 'highlight',
                  path: '/account/center',
                  component: './account/center',
                },
                // {
                //   name: 'settings',
                //   icon: 'smile',
                //   path: '/account/settings',
                //   component: './account/settings',
                // },
              ],
            },
            // {
            //   name: 'editor',
            //   icon: 'highlight',
            //   path: '/editor',
            //   routes: [
            //     {
            //       name: 'flow',
            //       icon: 'smile',
            //       path: '/editor/flow',
            //       component: './editor/flow',
            //     },
            //     {
            //       name: 'mind',
            //       icon: 'smile',
            //       path: '/editor/mind',
            //       component: './editor/mind',
            //     },
            //     {
            //       name: 'koni',
            //       icon: 'smile',
            //       path: '/editor/koni',
            //       component: './editor/koni',
            //     },
            //   ],
            // },
            {
              path: '/',
              redirect: '/user/login',
              // authority: ['admin','admin1','user'],
            },
            {
              component: '404',
            },
          ],
        },
      ],
    },
  ],
  // Theme for antd: https://ant.design/docs/react/customize-theme-cn
  theme: {
    // ...darkTheme,
    'primary-color': defaultSettings.primaryColor,
  },
  define: {
    REACT_APP_ENV: REACT_APP_ENV || false,
    ANT_DESIGN_PRO_ONLY_DO_NOT_USE_IN_YOUR_PRODUCTION:
      ANT_DESIGN_PRO_ONLY_DO_NOT_USE_IN_YOUR_PRODUCTION || '', // preview.pro.ant.design only do not use in your production ; preview.pro.ant.design 专用环境变量，请不要在你的项目中使用它。
  },
  ignoreMomentLocale: true,
  lessLoader: {
    javascriptEnabled: true,
  },
  cssLoader: {
    modules: {
      getLocalIdent: (context, _, localName) => {
        if (
          context.resourcePath.includes('node_modules') ||
          context.resourcePath.includes('ant.design.pro.less') ||
          context.resourcePath.includes('global.less')
        ) {
          return localName;
        }

        const match = context.resourcePath.match(/src(.*)/);

        if (match && match[1]) {
          const antdProPath = match[1].replace('.less', '');
          const arr = winPath(antdProPath)
            .split('/')
            .map(a => a.replace(/([A-Z])/g, '-$1'))
            .map(a => a.toLowerCase());
          return `antd-pro${arr.join('-')}-${localName}`.replace(/--/g, '-');
        }

        return localName;
      },
    },
  },
  manifest: {
    basePath: '/',
  },
  proxy: proxy[REACT_APP_ENV || 'dev'],
  chainWebpack: webpackPlugin,
});
